package com.youngking.guns.modular.weixin;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.weixin4j.Weixin;
import org.weixin4j.WeixinException;
import org.weixin4j.model.message.Articles;
import org.weixin4j.model.message.template.TemplateData;

import java.util.List;

@Controller
@RequestMapping("/sendMessage")
public class SendMessageController {
    /**
     * 发送文字消息
     * @param openid
     * @param content
     * @throws WeixinException
     */
    @RequestMapping("/sendContent")
    public  void SendContent(String openid,String content) throws WeixinException {
        Weixin weixin=new Weixin();
        //openid="oFDPj1JXaMS2oJcm4plrHfvlu0qg";
        //content="http://www.baidu.com";
        weixin.message().customSendContent(openid,content);

    }

    /**
     * 发送模板消息不带链接
     * @param openid
     * @param templateId
     * @param templateDataList
     * @throws WeixinException
     */
    @RequestMapping("/sendTemplateMessage")
    public  void sendTemplateMessage(String openid,String templateId,List<TemplateData> templateDataList) throws WeixinException {
        Weixin weixin=new Weixin();
        //openid="oFDPj1JXaMS2oJcm4plrHfvlu0qg";
        //templateId="ctgpHBwfhu-STdt4GjLfX8BHonDqe-9hyHa4Qo1lrnM";
        //TemplateData templateData=new TemplateData();
        //templateData.setColor("red");
        //templateData.setValue("www");
        //templateData.setKey("123321");
        //templateDataList=new ArrayList<>();
        //templateDataList.add(templateData);
        weixin.message().sendTemplateMessage(openid,templateId,templateDataList);


    }

    /**
     * 发送图文消息
     * @param openid
     * @param articlesList
     * @throws WeixinException
     */
    @RequestMapping("/sendNews")
    public void sendNews(String openid,List<Articles> articlesList ) throws WeixinException {
        Weixin weixin=new Weixin();
        weixin.message().customSendNews(openid,articlesList);
    }


    /**
     * 发送模板消息代链接
     * @param openid
     * @param templateId
     * @param templateDataList
     * @param url
     * @throws WeixinException
     */
    @RequestMapping("/sendTemplateMessageWithUrl")
    public void sendTemplateMessageWithUrl(String openid,String templateId,List<TemplateData> templateDataList,String url) throws WeixinException {
        Weixin weixin=new Weixin();
        weixin.message().sendTemplateMessage(openid,templateId,templateDataList,url);
    }
}
